//
//  ByNumberApi.m
//  caipiao_ios
//
//  Created by mc on 2018/7/30.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByNumberApi.h"

@implementation ByNumberApi


//大乐透开奖历史
+ (void)getLottoPrizeHistory:(ByNetModel *)model
                     success:(void(^)(ByNetBaseResult *result))success
                     failure:(void(^)(ByNetBaseResult *result))failure{
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [self post:@"/lotto/prize_his" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
}

+ (NSString *)toJSONData:(id)theData{
    
    NSError *error = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:theData
                                                       options:NSJSONWritingPrettyPrinted
                                                         error:&error];
    
    if ([jsonData length] > 0 && error == nil){
        return [[NSString alloc] initWithData:jsonData
                                     encoding:NSUTF8StringEncoding];;
    }else{
        return @"";
    }
}


//大乐透生成订单
+ (void)getLottoCreateOrder:(ByNetModel *)model
                    success:(void(^)(ByNetBaseResult *result))success
                    failure:(void(^)(ByNetBaseResult *result))failure{
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    if (model.numArray) {
        [params setObject:[self toJSONData:model.numArray] forKey:@"num"];
    }
    
   
    
    if (model.multiple) {
        [params setObject:model.multiple forKey:@"multiple"];
    }else{
        [params setObject:@"1" forKey:@"multiple"];
    }
    if (model.push_number) {
        [params setObject:model.push_number forKey:@"push_number"];
    }else{
        [params setObject:@"1" forKey:@"push_number"];
    }
    
    if (model.is_rand) {
        [params setObject:model.is_rand forKey:@"is_rand"];
    }else{
         [params setObject:@"0" forKey:@"is_rand"];
    }
    
    if (model.is_stop) {
        [params setObject:model.is_stop forKey:@"is_stop"];
    }else{
         [params setObject:@"0" forKey:@"is_stop"];
    }
    
    if (model.stop_money) {
        [params setObject:model.stop_money forKey:@"stop_money"];
    }else{
        [params setObject:@"0" forKey:@"stop_money"];
    }
    
    
    [self post:@"/lotto/create_order" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
    
    
}

//双色球开奖历史
+ (void)getColorBallPrizeHistory:(ByNetModel *)model
                         success:(void(^)(ByNetBaseResult *result))success
                         failure:(void(^)(ByNetBaseResult *result))failure{
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [self post:@"/color_ball/prize_his" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
    
    
}


//双色球订单生成
+ (void)getColorBallCreateOrder:(ByNetModel *)model
                        success:(void(^)(ByNetBaseResult *result))success
                        failure:(void(^)(ByNetBaseResult *result))failure{
    
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    
    if (model.numArray) {
        [params setObject:[self toJSONData:model.numArray] forKey:@"num"];
    }
    
    NSLog(@"array = %@", model.numArray);
    
    if (model.multiple) {
        [params setObject:model.multiple forKey:@"multiple"];
    }else{
        [params setObject:@"1" forKey:@"multiple"];
    }
    if (model.push_number) {
        [params setObject:model.push_number forKey:@"push_number"];
    }else{
        [params setObject:@"1" forKey:@"push_number"];
    }
    
    if (model.is_rand) {
        [params setObject:model.is_rand forKey:@"is_rand"];
    }else{
        [params setObject:@"1" forKey:@"is_rand"];
    }
    
    if (model.is_stop) {
        [params setObject:model.is_stop forKey:@"is_stop"];
    }else{
        [params setObject:@"0" forKey:@"is_stop"];
    }
    
    if (model.stop_money) {
        [params setObject:model.stop_money forKey:@"stop_money"];
    }else{
        [params setObject:@"0" forKey:@"stop_money"];
    }
    
    
    [self post:@"/color_ball/create_order" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
    
}

@end
